import axios from 'axios'
// const url = `http://localhost:4000`;
const url = `http://115.29.206.211:4000/`

// 创建axios实例对象
const http = axios.create({
  baseURL: url,
  timeout: 5000,
  //     headers: {
  //         token:localStorage.getItem('TOKEN')
  //    }
})

// 封装get请求
const get = (url: string, data = {}) => {
  return http.get(`${url}`, {
    params: data,
  })
}

// 封装POST请求
const post = (url: string, data = {}) => {
  return http
    .post(`${url}`, data, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: localStorage.getItem('TOKEN'),
      },
    })
    .then(response => response.data)
}

// 封装提交图片请求
const upload = (url: string, data = {}) => {
  return http
    .post(`${url}`, data, {
      headers: {
        'Content-Type': 'multipart/form-data',
        token: localStorage.getItem('TOKEN'),
      },
    })
    .then(response => response.data)
}

// 到处属性和方法
// 日后这里放真实的地址
export default {
  // url:`http://localhost:4000`,
  url: `http://115.29.206.211:4000`,
  get,
  post,
  upload,
}

//
